home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_56 / mem2mem.asm < prev    next >
Encoding:
Assembly Source File  |  1995-01-01  |  5.2 KB  |  222 lines

  1. ;==============================================================================
  2. ; memory to memory transfer
  3. ;   AndrĂ© Baresel
  4. ;------------------------------------------------------------------------------
  5. ; Requirements: 80286, DOS 1.0,
  6. ;
  7.  
  8.     .MODEL small
  9.     .286
  10.  
  11.     ; DMA controller registers :
  12.     WRITEMASK          EQU 00ah         ;WRITE MASK REGISTER
  13.     WRITEMODE          EQU 00bh         ;WRITE MODE REGISTER
  14.     COMMAND            EQU 008h         ;WRITE COMMAND REGISTER
  15.     STATUS             EQU 008h         ;READ STATUS REGISTER
  16.     START              EQU 009h         ;WRITE START REGISTER
  17.     CLEARFLIPFLOP      EQU 00ch
  18.  
  19.     PAGE_CHN0          EQU 087h         ;PAGE REGISTER FOR DMAchannel 0
  20.     BASE_CHN0          EQU 000h         ;BASEADDRESS REGISTER DMA 0
  21.     COUNT_CHN0         EQU 001h         ;COUNT REGISTER DMAchannel 0
  22.  
  23.     PAGE_CHN1          EQU 083h         ;PAGE REGISTER FOR DMAchannel 1
  24.     BASE_CHN1          EQU 002h         ;BASEADDRESS REGISTER DMA 1
  25.     COUNT_CHN1         EQU 003h         ;COUNT REGISTER DMAchannel 1
  26.  
  27.     ; for DMA COMMAND REGISTER
  28.     COMMANDVALUE       EQU 00000001b
  29.     ; for DMA WRITE MODE REGISTER
  30.     MODE_CH0           EQU 00000100b  ; singlemode, nonautoinit, writemode ch0
  31.     MODE_CH1           EQU 00001001b  ; singlemode, nonautoinit, readmode ch1
  32.  
  33.     .STACK 100h
  34.  
  35.     .DATA
  36.  
  37.     origintxt   db 13,10,'Data to copy :',13,10
  38.     origin      db 80 DUP ('#')
  39.                 db '$'
  40.     destitxt    db 13,10,'Destination (F stand for not copied right):',13,10
  41.     destination db 80 DUP (01h)
  42.                 db '$'
  43.  
  44.     override    db  'I',39,'m sorry a DMA page override ...','$'
  45.     errorcopy   db  'Hmm, somethings going wrong while copying with DMA ...','$'
  46.     ok          db  1
  47.  
  48.     .CODE
  49.     .STARTUP
  50.  
  51.     ;
  52.     ; calculate page and offset for DMAcontroller :
  53.     ;
  54.     ; segment*16+offset - 20bit memory location -> upper 4 bits  = page
  55.     ;                                              lower 16 bits = offset
  56.     ;
  57.     mov     si,offset origin
  58.     mov     di,offset destination
  59.     mov     ax,ds
  60.     rol     ax,4
  61.     mov     bl,al
  62.     and     bl,00fh
  63.     mov     bh,bl
  64.     and     al,0f0h
  65.     add     si,ax        ; offset for origin (channel 0)
  66.     adc     bh,0         ; page for origin (channel 0)
  67.     add     di,ax        ; offset for destination (channel 1)
  68.     adc     bl,0         ; page for destination (channel 1)
  69.  
  70.     cmp     si,-80
  71.     jna     ok1         ; shit a page override
  72.     jmp     exit
  73. ok1:
  74.     cmp     di,-80
  75.     jna     ok2         ; shit a page override
  76.     jmp     exit
  77. ok2:
  78.     ;
  79.     ; Setup channel 0:
  80.     ;
  81.     ; 1st  mask DMA channel 0
  82.     ;
  83.     mov     al,4
  84.     out     WRITEMASK,al
  85.     ;
  86.     ; 2nd  clear flipflop
  87.     ;
  88.     out     CLEARFLIPFLOP,al
  89.     ;
  90.     ; 3rd  write transfer mode
  91.     ;
  92.     mov     al,MODE_CH0
  93.     out     WRITEMODE,al
  94.     ;
  95.     ; 4th  write PAGE number
  96.     ;
  97.     mov     al,bh
  98.     out     PAGE_CHN0,al
  99.     ;
  100.     ; 5th  write baseaddress
  101.     ;
  102.     mov     ax,si
  103.     out     BASE_CHN0,al
  104.     mov     al,ah
  105.     out     BASE_CHN0,al
  106.     ;
  107.     ; 6th  write samplelength-1
  108.     ;
  109.     mov     cx,80-1
  110.     mov     al,cl
  111.     out     COUNT_CHN0,al
  112.     mov     al,ch
  113.     out     COUNT_CHN0,al
  114.     ;
  115.     ; 7th  demask channel 0
  116.     ;
  117.     mov     al,0
  118.     out     WRITEMASK,al
  119.  
  120.     ; ------------- channel 0 setup ok -------------------
  121.  
  122.     ;
  123.     ; Setup channel 1:
  124.     ;
  125.     ; 1st  mask DMA channel 1
  126.     ;
  127.     mov     al,5
  128.     out     WRITEMASK,al
  129.     ;
  130.     ; 2nd  clear flipflop
  131.     ;
  132.     out     CLEARFLIPFLOP,al
  133.     ;
  134.     ; 3rd  write transfer mode
  135.     ;
  136.     mov     al,MODE_CH1
  137.     out     WRITEMODE,al
  138.     ;
  139.     ; 4th  write PAGE number
  140.     ;
  141.     mov     al,bl
  142.     out     PAGE_CHN1,al
  143.     ;
  144.     ; 5th  write baseaddress
  145.     ;
  146.     mov     ax,di
  147.     out     BASE_CHN1,al
  148.     mov     al,ah
  149.     out     BASE_CHN1,al
  150.     ;
  151.     ; 6th  write samplelength-1
  152.     ;
  153.     mov     cx,80-1
  154.     mov     al,cl
  155.     out     COUNT_CHN1,al
  156.     mov     al,ch
  157.     out     COUNT_CHN1,al
  158.     ;
  159.     ; 7th  demask channel 1
  160.     ;
  161.     mov     al,1
  162.     out     WRITEMASK,al
  163.  
  164.     ; ------------- channel 1 setup ok -------------------
  165.  
  166.     ; set command :
  167.     mov     al,commandvalue
  168.     out     command,al
  169.  
  170.     ; start transfer :
  171.     mov     al,00000100b
  172.     out     START,al
  173.  
  174. waitforterminal:
  175.     in      al,STATUS
  176.     and     al,1
  177.     jz      waitforterminal
  178.  
  179.     ; compare it :
  180.     mov     cx,80
  181.     mov     si,offset origin
  182.     mov     di,offset destination
  183. cloop:
  184.     lodsb
  185.     cmp     al,ds:[di]
  186.     je      next
  187.     mov     ds:[di],byte ptr 'F'
  188.     mov        [ok],0
  189. next:
  190.     inc     di
  191.     loop    cloop
  192.  
  193.     ; let's show the result
  194.     mov     dx,offset origintxt
  195.     mov     ah,9
  196.     int     21h
  197.  
  198.     mov     dx,offset destitxt
  199.     mov     ah,9
  200.     int     21h
  201.  
  202.     cmp     [ok],1
  203.     jne     notcopied
  204.  
  205. exit:
  206.     ; Terminate EXE:
  207. return2dos:
  208.     mov     ax,04c00h
  209.     int     21h
  210.  
  211. over:  mov     dx,offset override
  212.        mov     ah,9
  213.        int     21h
  214.        jmp     exit
  215.  
  216. notcopied: mov     dx,offset errorcopy
  217.            mov     ah,9
  218.            int     21h
  219.            jmp     exit
  220.  
  221.     END
  222.